var CreateContainer = /** @class */ (function () {
    function CreateContainer(width, height, scale, PIXI, app) {
        if (width === void 0) { width = 0; }
        if (height === void 0) { height = 0; }
        if (scale === void 0) { scale = 0; }
        if (PIXI === void 0) { PIXI = null; }
        if (app === void 0) { app = null; }
        var _this = this;
        this._Sprite = null;
        this._rotation = 0;
        this._width = 120;
        this._scale = 1;
        this.PIXI = null;
        this.canClick = true;
        this._height = 163;
        this.rotateArr = [0, 15, 30, 45, -15, -30, -45];
        this.minX = 0;
        this.maxX = 0;
        this.maxY = 0;
        this.startY = 0;
        this._position = {
            x: 0,
            y: 0
        };
        this._speed = 3;
        if (PIXI) {
            this.PIXI = PIXI;
            this._Sprite = this.PIXI.Sprite;
            this._scale = scale;
        }
        this._rotation = Math.floor(Math.random() * this.rotateArr.length) * 90;
        this._width = this._width * this._scale;
        this._height = this._height * this._scale;
        this.minX = this._height;
        this.maxX = width - this._width;
        this.maxY = height;
        this.startY = this._height + 10;
        this._position = {
            x: this.minX + Math.floor(Math.random() * (this.maxX - this.minX)),
            y: this.startY
        };
        this._body = new this.PIXI.Container;
        this._body.width = this._width;
        this._body.height = this._height;
        this.init();
        EventDispatcher.addEventListener('updateData', function () { _this.update(); }, this);
    }
    CreateContainer.prototype.addEventListenerHandler = function () {
        var _this = this;
        this._body.interactive = true;
        this._body.on('pointerdown', function (e) { _this.pointerdown(); });
    };
    CreateContainer.prototype.pointerdown = function () {
        if (this.canClick) {
            this.canClick = false;
            this.doAjax();
        }
    };
    CreateContainer.prototype.doAjax = function () {
        var _this = this;
		console.log('点击')
        this._body.destroy();
        EventDispatcher.removeEventListener('updateData', function () { _this.update(); }, this);
		$.ajax({
			url:'https://h5.jtsummit.cn/jingling2009/luck/get',
			method:'post',
			dataType:'json',
			data:{
				round:sessionStorage.getItem('redRound')
			},
			success:function(res){
				console.log(res)
				if(res.code == '0000'){
					
					EventDispatcher.dispatchEvent('stopSelf', 'event');
					alert('恭喜你，中奖啦');
				}else if(res.code == '0001'){
					
					EventDispatcher.dispatchEvent('stopSelf', 'event');
					alert(res.msg);
				}else{
					alert(res.msg)
				}
			}
		})
    };
    CreateContainer.prototype.init = function () {
        this._sprite = this._Sprite.from('https://jinlingguan202009.oss-cn-beijing.aliyuncs.com/img/redbucket.png');
        this._sprite.width = this._width;
        this._sprite.height = this._height;
        this._sprite.rotation = this._rotation;
        this._sprite.position.set(this._position.x, this._position.y);
        this._sprite.anchor.set(0.5, 0.5);
        this._body.addChild(this._sprite);
        this.addEventListenerHandler();
    };
    CreateContainer.prototype.update = function () {
        this._position.y += this._speed;
        this._sprite.position.set(this._position.x, this._position.y);
        this.checkList();
    };
    CreateContainer.prototype.checkList = function () {
        var _this = this;
        if (this._position.y >= this.maxY + this._height + 10) {
            EventDispatcher.removeEventListener('updateData', function () { _this.update(); }, this);
            this._body.destroy();
        }
    };
    return CreateContainer;
}());


var PixiApp = /** @class */ (function () {
    function PixiApp(obj) {
        if (obj === void 0) { obj = { width: 0, height: 0, stage: null, PIXI: null, app: null }; }
        this.width = 0;
        this.height = 0;
        this.PIXI = null;
        this.interval = null;
        if (obj.width) {
            this.width = obj.width;
        }
        if (obj.height) {
            this.height = obj.height;
        }
        if (obj.stage) {
            this.stage = obj.stage;
        }
        if (obj.PIXI) {
            this.PIXI = obj.PIXI;
        }
        if (obj.app) {
            this.app = obj.app;
        }
    }
    PixiApp.prototype.init = function () {
        var _this = this;
        this.container = new this.PIXI.Container();
        this.container.width = this.width;
        this.container.height = this.height;
        this.container.x = 0;
        this.container.y = 0;
        this.stage.addChild(this.container);
		EventDispatcher.addEventListener('stopSelf', function () { _this.stop(); }, this);
        this.createRedBucket();
        this.app.ticker.add(function () {
            _this.updataSprite();
        });
    };
    // 创建元素
    PixiApp.prototype.createRedBucket = function () {
        var _this = this;
        this.interval = setInterval(function () {
            _this.container.addChild(new CreateContainer(_this.width, _this.height, 0.3, _this.PIXI, _this.app)._body);
        }, 300);
    };
    PixiApp.prototype.updataSprite = function () {
        EventDispatcher.dispatchEvent('updateData', 'event');
    };
    PixiApp.prototype.stop = function () {
        this.app.ticker.stop();
        this.container.removeChildren();
        this.container.destroy();
		
        clearInterval(this.interval);
		$('.canvas_wrap').fadeOut(0);
    };
    return PixiApp;
}());
